{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "HyperTS针对不同的模式内置了丰富的建模算法，例如:\n",
    "- StatsForecastSearchSpace: 预测任务统计模型搜索空间，内置了Prophet、ARIMA及VAR等统计模型;\n",
    "- StatsClassificationSearchSpace: 分类任务统计模型搜索空间，内置了TSForest, k-NNs等统计模型;\n",
    "- DLForecastSearchSpace: 预测任务深度模型搜索空间，内置DeepAR、RNN、GPU、LSTM及LSTNet等深度模型;\n",
    "- DLClassificationSearchSpace: 分类任务深度模型搜索空间，内置RNN、GPU、LSTM及LSTNet等深度模型;\n",
    "  \n",
    "以上建模算法均设计了各自默认的超参数搜索空间。如果您想在此基础上定制化自己的搜索空间，则可以在调用```make_experiment```时通过参数search_space指定自定义的搜索空间。\n",
    "\n",
    "假如现在我们想修改预测任务下的统计模式的搜索空间, 即```StatsForecastSearchSpace```,您可以做如下操作：\n",
    "- ~详细指定任务类型```task```, 否则无法判断是单变量预测还是多变量预测任务;~\n",
    "- ~指定```timestamp```列名;~\n",
    "- ~如果数据存在协变量，请设置参数```covariables```;~\n",
    "- ~**以上三步请严格遵守, 否则自定义失败！**~\n",
    "- 如果想禁止某个算法，不进行搜索，可以设置参数为False, 例如```enable_arima=False```;\n",
    "- 如果想更改某个算法的搜索空间参数初始化，可以传递参数```xxx_init_kwargs={xxx:xxx, ...}```;\n",
    "- 如果希望自定义的参数是可搜索的, 您可以使用```hypernets.core.search_space```中的```Choice```, ```Int``` 及 ```Real```。其中，```Choice```支持离散值，```Int```支持整数连续值, ```Real```支持浮点数连续值。详情可参考[Search Space](https://github.com/DataCanvasIO/Hypernets/blob/master/hypernets/core/search_space.py)。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**注意**\n",
    "\n",
    "- 我们简化了搜索空间的自定义，从而可以不用再传task,timestamp,covariables等参数。\n",
    "- 详情参见**更新**。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from hypernets.core.search_space import Choice, Int, Real\n",
    "from hyperts.framework.search_space.macro_search_space import StatsForecastSearchSpace\n",
    "\n",
    "custom_search_space = StatsForecastSearchSpace(task='univariate-forecast', \n",
    "                                               timestamp='TimeStamp',\n",
    "                                               covariables=['HourSin', 'WeekCos', 'CBWD'],\n",
    "                                               enable_arima=False,\n",
    "                                               prophet_init_kwargs={\n",
    "                                                   'seasonality_mode': 'multiplicative',\n",
    "                                                   'daily_seasonality': Choice([True, False]),\n",
    "                                                   'n_changepoints': Int(10, 50, step=10),\n",
    "                                                   'interval_width': Real(0.1, 0.5, step=0.1)}\n",
    "                                               )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from hyperts import make_experiment\n",
    "\n",
    "experiment = make_experiment(train_data, \n",
    "                             task='univariate-forecast',\n",
    "                             timestamp='TimeStamp',\n",
    "                             covariables=['HourSin', 'WeekCos', 'CBWD'],\n",
    "                             search_space=custom_search_space,\n",
    "                             ...) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 更新"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from hypernets.core.search_space import Choice, Int, Real\n",
    "from hyperts.framework.search_space.macro_search_space import StatsForecastSearchSpace\n",
    "\n",
    "custom_search_space = StatsForecastSearchSpace(enable_arima=False,\n",
    "                                               prophet_init_kwargs={\n",
    "                                                   'seasonality_mode': 'multiplicative',\n",
    "                                                   'daily_seasonality': Choice([True, False]),\n",
    "                                                   'n_changepoints': Int(10, 50, step=10),\n",
    "                                                   'interval_width': Real(0.1, 0.5, step=0.1)}\n",
    "                                               )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from hyperts import make_experiment\n",
    "\n",
    "experiment = make_experiment(train_data, \n",
    "                             task='univariate-forecast',\n",
    "                             timestamp='TimeStamp',\n",
    "                             covariables=['HourSin', 'WeekCos', 'CBWD'],\n",
    "                             search_space=custom_search_space,\n",
    "                             ...) "
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "29dd11bf16d40fe19950dcc2f06dd773fb6bc4491ac296fb211bfed7a4a532da"
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
